﻿@using Orchard.Comments.Models;
@using Orchard.Comments;
@using Orchard.Security;
@using Orchard.Utility.Extensions;

@{
    var contextExists = TempData["CreateCommentContext.Name"] != null;
    var name = Convert.ToString(TempData["CreateCommentContext.Name"]);
    var commentText = Convert.ToString(TempData["CreateCommentContext.CommentText"]);
    var email = Convert.ToString(TempData["CreateCommentContext.Email"]);
    var siteName = Convert.ToString(TempData["CreateCommentContext.SiteName"]);
}

@if (Model.ContentPart.Comments.Count > 0) {
    <div id="comments" style="padding-top: 25px;">
        <h4><span class="comments-amount">@T.Plural("Comments (1)", "Comments ({0})", (int)Model.ContentPart.Comments.Count)</span></h4>
        <div class="comments-sec">
            @{Html.RenderPartial("ListOfComments", (IEnumerable<Orchard.Comments.Models.CommentPart>)Model.ContentPart.Comments);}
        </div>
    </div>
}

@if (Model.ContentPart.CommentsActive == false) {
    if (Model.ContentPart.Comments.Count > 0) {
    <div id="comments">
        <p class="comment-disabled">@T("Comments have been disabled for this content.")</p>
    </div>
    }
}
else if (WorkContext.CurrentUser == null && !AuthorizedFor(Permissions.AddComment)) {
    <div class="clear"></div>
    <h4 id="add-comment">@T("Leave a Comment")</h4>
    <div class="form-spacer"></div>
    <p class="info message">@T("You must {0} to comment.", Html.ActionLink(T("log on").ToString(), "LogOn", new { Controller = "Account", Area = "Orchard.Users", ReturnUrl = string.Format("{0}#addacomment", Context.Request.RawUrl) }))</p>
}
else {
    <div class="clear"></div>
    using (Html.BeginForm("Create", "Comment", new { area = "Orchard.Comments" }, FormMethod.Post, new { @class = "comment-form" })) { 
    @Html.ValidationSummary() 
        if (WorkContext.CurrentUser == null) {

    <fieldset class="who">
        <h4>@T("Leave a Comment")</h4>
        <div class="form-spacer"></div>
        <div id="contact-form">
            <div class="field">
                <label for="Name">@T("Name: ")</label>
                <input id="Name" class="text" name="Name" type="text" value="@(contextExists ? name : String.Empty)" />
            </div>
            <div class="field">
                <label for="Email">@T("Email: ")<span>*</span></label>
                <input id="Email" class="text" name="Email" type="text" value="@(contextExists ? email : String.Empty)"/>
            </div>
            <div class="field">
                <label for="SiteName">@T("Url: ")</label>
                <input id="SiteName" class="text" name="SiteName" type="text" value="@(contextExists ? siteName : String.Empty)"/>
            </div>
        </div>
    </fieldset>
        }
        else {
    @Html.Hidden("Name", WorkContext.CurrentUser.UserName ?? "")
    @Html.Hidden("Email", WorkContext.CurrentUser.Email ?? "")
        }

    <fieldset class="what">
            <div class="field">
                <label for="comment-text">@T("Message: ")<span>*</span></label>
                <textarea id="comment-text" class="text textarea" rows="10" cols="30" name="CommentText">@(contextExists ? commentText : String.Empty)</textarea>
            </div>
            <div class="field">
                <button class="button color" type="submit">@T("Add Comment")</button>
                @Html.Hidden("CommentedOn", (int)Model.ContentPart.ContentItem.Id)
                @Html.Hidden("ReturnUrl", Context.Request.ToUrlString())
                @Html.AntiForgeryTokenOrchard()
            </div>
    </fieldset>
    }
}
